package com.hrt.web.shoppingCar.dao.impl;


import java.util.List;

import org.springframework.stereotype.Repository;

import com.hrt.base.BaseDaoImpl;
import com.hrt.bean.ShoppingCar;
import com.hrt.web.shoppingCar.dao.ShoppingCarDao;
@Repository
@SuppressWarnings("unchecked")
public class ShoppingCarDaoImpl extends BaseDaoImpl<ShoppingCar> implements ShoppingCarDao{
	/**
	 * 根据memberId查找购物车
	 * @param memberId
	 * @return
	 */
	@Override
	public Long getCarByMemberId(Long memberId) {
		String hql = "select car from ShoppingCar car where car.memberId="+memberId+" and car.isdelete=0";
		
		return (long) getHibernateTemplate().find(hql).size();
	}

	
	@Override
	public List<ShoppingCar> getShoppingCarByMemberId(Long memberId) {
		String hql = "select car from ShoppingCar car where car.memberId="+memberId+" and car.isdelete=0";
		
		return getHibernateTemplate().find(hql);
	}


	@Override
	public ShoppingCar getCarById(Long CarId) {
		ShoppingCar  shoppingCar = null;
		String hql = "select car from ShoppingCar car where car.id="+CarId+" and car.isdelete=0";
		List list = getHibernateTemplate().find(hql);
		if(list!=null&&list.size()>0){
			shoppingCar = (ShoppingCar) list.get(0);
		}
		return shoppingCar;
	}


	@Override
	public ShoppingCar getCarByMbrAndGI(Long memberId, Long id) {
		ShoppingCar  shoppingCar = null;
		String hql ="select car from ShoppingCar car where car.memberId='"+memberId+"' and car.giDetailId='"+id+"' and car.isdelete=0";
		List list = getHibernateTemplate().find(hql);
		if(list!=null&&list.size()>0){
			shoppingCar = (ShoppingCar) list.get(0);
		}
		
		return shoppingCar;
	}



}
